///#Square-Root Diffusion(CIR模型) 平方根扩散模型

pub struct CIR {
    pub S0: f64,
    pub T: f64,
    pub steps: usize,
    /// 标准差形式
    pub sigma: f64,
    /// long term mean
    pub mu: f64,
    /// 调整速率
    pub kappa: f64,
}

impl Stochastic for CIR {
    fn gen_path(&self) -> Vec<f64> {
        let dt = self.T / self.steps as f64;
        let mut res = Vec::new();
        let mut x = self.S0;
        res.push(x);
        for step in 0..self.steps {
            let z = random_from_stdnorm();
            let n1 = self.kappa * (self.mu - x) * dt;
            let n2 = self.sigma * x.sqrt() * dt.sqrt() * z;
            x = x + n1 + n2;
            res.push(x);
        }
        res
    }
}
